package com.thirteen.app.controller;

import com.thirteen.app.dto.PaperWithAnswerResponse.PaperWithAnswerDto;
import com.thirteen.app.dto.JudgeSubjectiveResquest.JudgeByPersonDto;
import com.thirteen.app.dto.PaperWithScoreResponse.PaperWithScoreDto;
import com.thirteen.app.service.ExamRecordService;
import com.thirteen.app.service.JudgeService;
import com.thirteen.app.service.PaperService;
import com.thirteen.app.utils.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(tags = {"老师阅卷"})
@RestController
@RequestMapping("/api")
@CrossOrigin
public class JudgeController {

    @Resource
    private ExamRecordService examRecordService;

    @Resource
    private JudgeService judgeServicee;

    @ApiOperation("提交阅卷结果")
    @PostMapping("/teacher/exam/commitJudge")
    public CommonResult submitJudge(@RequestBody JudgeByPersonDto judgeByPersonDto) {
        System.out.println(judgeByPersonDto.toString());
        try {
            if(!judgeServicee.judgeByPerson(judgeByPersonDto)){
                return CommonResult.failed("阅卷失败");
            }
            examRecordService.updateScore(judgeByPersonDto);
        } catch (Exception e) {
            return CommonResult.failed("阅卷失败");
        }
        return CommonResult.success(judgeByPersonDto);
    }



}
